home *** CD-ROM | disk | FTP | other *** search
/ The Mac 13 / the-mac-13.iso / Shareware City / Demos / TextPak Demo / Extras / GlossaryDatabase.k < prev    next >
Encoding:
Text File  |  1995-06-09  |  5.0 KB  |  199 lines  |  [TEXT/MPS ]

  1. --
  2. --     © 1994, 1995 Art of Memory Ltd.
  3. --     All Rights Reserved
  4. --
  5. -- This file is supplied as part of the TextPak demonstration. You are only
  6. -- entitled to use this software to understand how the demonstration works.
  7. -- You may not duplicate, modify, reproduce or distribute this software in
  8. -- any form. If you wish to purchase a licence to use this software, please
  9. -- contact Art of Memory Ltd.
  10. --
  11.  
  12. object GlossaryDatabase is MultimediaDatabase
  13.  
  14. has
  15.     
  16.     ----------------------------------------------------------------------------------------------
  17.     --
  18.     -- DATA ACCESS METHODS
  19.     --
  20.     --
  21.     
  22.     -- Return a list (collection) of glossary entries whose names
  23.     -- start with a given letter of the alphabet
  24.     -- The search assumes the glossarties are in alphabetical
  25.     -- order: once it has found one entry that starts with the
  26.     -- correct name, it continues until it finds an entry with
  27.     -- a non-correct initial letter and then ends the search.
  28.     GetGlossaryList(firstLetter)
  29.         firstLetter is? CHARACTER;
  30.     
  31.     use
  32.         loopCount;
  33.         nextGlossaryEntry;
  34.         foundStart;
  35.         foundEnd;
  36.         registerSize;
  37.         
  38.     do
  39.         if APPLICATION.MouseSpin <> void then
  40.             APPLICATION.MouseSpin.Start();
  41.         end;
  42.         
  43.         result := new COLLECTION;
  44.         
  45.         -- Convert the letter to lower case to ease matching
  46.         firstLetter := FirstLetter.Lower();
  47.         
  48.         from
  49.             loopCount    := 1;
  50.             foundStart   := false;
  51.             --foundEnd     := false;
  52.             registerSize := #self.Register;
  53.         until (loopCount>registerSize) loop --or foundEnd loop
  54.         
  55.             nextGlossaryEntry := self.Register @ loopCount;
  56.             
  57.             if ((((nextGlossaryEntry.LowerCaseName) @ 1) - firstLetter)=0) then
  58.                 if (nextGlossaryEntry.TextPath @ 1)<>'+' then
  59.                     result.Append(nextGlossaryEntry);
  60.                 end;
  61.             end;
  62.         
  63.         step
  64.             loopCount := loopCount + 1;
  65.         end;
  66.         
  67.         if APPLICATION.MouseSpin <> void then
  68.             APPLICATION.MouseSpin.Stop();
  69.         end;
  70.     end;
  71.  
  72.     
  73.     -- Find a glossary entry whose name is glossaryWord or which
  74.     -- has glossaryWord on its synonym list. If there is no such
  75.     -- entry, return void, otherwise return the entry itself
  76.     FindGlossaryEntry(glossaryWord)
  77.         glossaryWord is? STRING;
  78.         
  79.     use
  80.         loopCount;
  81.         innerLoop;
  82.         nextGlossaryEntry;
  83.         listSize;
  84.         registerSize;
  85.         
  86.     do
  87.         
  88.         if APPLICATION.MouseSpin <> void then
  89.             APPLICATION.MouseSpin.Start();
  90.         end;
  91.         
  92.         glossaryWord := StringLibrary.LowerCase(glossaryWord);
  93.         
  94.         from
  95.             loopCount    := 1;
  96.             registerSize := #self.Register;
  97.         until (loopCount>registerSize) or (result<>void) loop
  98.         
  99.             nextGlossaryEntry := self.register @ loopCount;
  100.             
  101.             if StringLibrary.StringEqual(nextGlossaryEntry.lowerCaseName,glossaryWord) then
  102.                 result  := nextGlossaryEntry;
  103.             else
  104.                 listSize := #nextGlossaryEntry.LowerCaseSynonymList;
  105.                 if listSize>0 then
  106.                     from
  107.                         innerLoop := 1;
  108.                     until innerLoop>listSize loop
  109.                         if StringLibrary.StringEqual(nextGlossaryEntry.LowerCaseSynonymList @ innerLoop, glossaryWord) then
  110.                             result := nextGlossaryEntry;
  111.                         end;
  112.                     step
  113.                         innerLoop := innerLoop + 1;
  114.                     end;
  115.                 end;
  116.             end;
  117.         
  118.         step
  119.             loopCount := loopCount + 1;
  120.         end;
  121.         
  122.         if result=void then
  123.             UserTracer.AddTrace("Cannot find glossary entry " + glossaryWord);
  124.         end;
  125.         
  126.         if APPLICATION.MouseSpin <> void then
  127.             APPLICATION.MouseSpin.Stop();
  128.         end;
  129.     end;
  130.     
  131.  
  132. end;
  133.  
  134.  
  135. --
  136. -- AUTHOR:    Dan Crow
  137. --
  138. -- DATE:    20/03/94
  139. --
  140. -- A glossaryComponent holds information about a single
  141. -- glossary entry
  142. class glossaryComponent is databaseComponent;
  143.  
  144. has
  145.  
  146.     Name;                    -- The name (trigger word) of the glossary entry
  147.     LowerCaseName;            -- The glossary name converted to lower case
  148.     SynonymList;            -- List of synonyms for the glossary entry
  149.     LowerCaseSynonymList;    -- The synonym list converted to lower case
  150.     TextPath;                -- Name of text file containing the glossary text
  151.     TechniqueLink;            -- (Optional) Making of Glass technique to link to
  152.  
  153.     ParseComponentData(dataList)
  154.         dataList is? COLLECTION;
  155.     
  156.     use
  157.         synList;
  158.         synListSize;
  159.         loopCount;
  160.         
  161.     do
  162.     
  163.         self.Name := dataList @ 1;
  164.         --DanDebug.ShowAlert("Parsing glossary entry with name=" + self.Name);
  165.         --APPLICATION.Refresh();
  166.         self.LowerCaseName := StringLibrary.LowerCase(self.Name);
  167.         synList := dataList @ 2;
  168.         --DanDebug.ShowAlert("Name=" + self.Name + " synList=<" + synList + ">");
  169.         
  170.         if synList<>void then
  171.             self.SynonymList := StringLibrary.StringToList(synList,',');
  172.             synListSize      := #self.synonymList;
  173.             from
  174.                 self.LowerCaseSynonymList := new COLLECTION;
  175.                 loopCount                 := 1;
  176.             until loopCount>synListSize loop
  177.                 if (self.synonymList @ loopCount)<>void then
  178.                     self.LowerCaseSynonymList.Append(StringLibrary.LowerCase(self.synonymList @ loopCount), loopCount);
  179.                 end;
  180.             step
  181.                 loopCount := loopCount + 1;
  182.             end;
  183.         else
  184.             self.SynonymList          := new COLLECTION;
  185.             self.LowerCaseSynonymList := new COLLECTION;
  186.         end;
  187.         
  188.         self.TextPath := dataList @ 3;
  189.         
  190.         -- If there is a fourth list item, its the Making of Glass
  191.         -- technique to link to
  192.         self.TechniqueLink := void;
  193.         if #dataList>3 then
  194.             if (dataList @ 4) is? STRING then
  195.                 self.TechniqueLink := dataList @ 4;
  196.             end;
  197.         end;
  198.     end;
  199. end;